{extend name="../public/header" /}
{block name="body"}
<link rel="stylesheet" href="/public/admin/css/other.css" type="text/css">
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('')}">
			<section class="panel panel-padding">
				<div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-inline">
						<input type="text" name="zbname" value="{$info.zbname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">介绍</label>
					<div class="layui-input-inline">
						<textarea name="zbinfo" placeholder="请输入介绍" class="layui-textarea">{$info.zbinfo|default=''}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">等级</label>
					<div class="layui-input-inline">
						<input type="text" name="zblv" value="{$info.zblv|default='0'}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">部位</label>
					<div class="layui-input-inline">
						<select name="zbtool" required lay-verify="required">
							<option value="">请选择</option>
							{volist name='zbtool_list' id='vo' key='k'}
							<option value="{$k}" {if condition="$vo eq $info.zbtool"}selected{/if}>{$vo}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-upload" id="pic_img">
					<span class="fileinput-button">
						<span class="layui-btn">上传缩略图</span>
						<input type="file" id="pic" class="layui-btn file" accept="image/gif,image/jpg,image/jpeg,image/x-png"/>
					</span>
					<div class="layui-upload-list">
						<a href="{$info.thumb}" target="_blank"><img class="layui-upload-img" {if !empty($info.thumb)}src="{$info.thumb}"{/if} ></a>
						<input name="thumb" type="hidden" value="{$info.thumb|default=''}"/>
					</div>
				</div>
				<fieldset class="layui-elem-field">
					<legend>属性</legend>
					<div class="layui-field-box">
						<div class="layui-row">
							<div class="layui-form-item">
								<label class="layui-form-label">生命</label>
								<div class="layui-input-inline">
									<input type="text" name="zbhp" value="{$info.zbhp|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">攻击</label>
								<div class="layui-input-inline">
									<input type="text" name="zbgj" value="{$info.zbgj|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">防御</label>
								<div class="layui-input-inline">
									<input type="text" name="zbfy" value="{$info.zbfy|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">暴击</label>
								<div class="layui-input-inline">
									<input type="text" name="zbbj" value="{$info.zbbj|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">吸血</label>
								<div class="layui-input-inline">
									<input type="text" name="zbxx" value="{$info.zbxx|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">速度</label>
								<div class="layui-input-inline">
									<input type="text" name="zbsd" value="{$info.zbsd|default='0'}" class="layui-input">
								</div>
							</div>
						</div>
					</div>
				</fieldset>
				<!-- / -->

				<div class="layui-input-block">
					<input type="hidden" name="zbid" type="hidden" value="{$info.zbid|default=''}">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</section>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	//单图上传 缩略图
	$('#pic_img .file').change(function(event) {
		layer.msg('正在上传中',{icon:6,time:10000});
		var formData = new FormData();
		formData.append("file", $(this).get(0).files[0]);
		$.ajax({
			url:'{:url("upload/upFile")}',
			type:'POST',
			data:formData,
			cache: false,
			contentType: false,    //不可缺
			processData: false,    //不可缺
			success:function(res){
				console.log('res',res);
				layer.close(layer.index);

				if (res.code == undefined) {
					console.log('res为json字符串', res);
					res = JSON.parse(res);
				} else {
					console.log('res为json对象', res);
				}

				//如果上传失败
				if(res.code != 1){
					return layer.msg('上传失败');
				}else{
					//上传成功
					layer.msg(res.msg,{icon:1,time:2000});

					var data = res.data;
					$('#pic_img .layui-upload-list a').attr('href', data.picurl);
					$('#pic_img .layui-upload-list img').attr('src', data.picurl);
					$('#pic_img .layui-upload-list input').val(data.picurl);
				}
			},
			error: function(res){
				console.log(res);
			}
		});
	});

	form.render();
});
</script>
{/block}